from django.db import models
from travel.models import Travel


class User(models.Model):
    username = models.CharField('账号', max_length=55, default='')
    password = models.CharField('密码', max_length=55, default='')
    name = models.CharField('昵称', max_length=55, default='')
    avatar = models.CharField('头像', max_length=200, default='')
    role = models.CharField('角色', max_length=200, default='USER')
    age = models.IntegerField('年龄', default=18)
    gender = models.CharField('性别', max_length=2, default='保密')
    address = models.CharField('住址', max_length=100, default='', blank=True, null=True)
    tags = models.JSONField('喜好列表', default='')
    create_time = models.DateTimeField('创建时间', auto_now_add=True)

    def is_authenticated(self):
        return True


class UserComments(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    travel = models.ForeignKey(Travel, on_delete=models.CASCADE)
    # null：字段可以设为空值 blank：django校验时可以为空值
    content = models.TextField('评论内容', default='', null=True, blank=True)
    score = models.FloatField('评分', default=0)
    img_list = models.JSONField('图片列表', default='')
    create_time = models.DateTimeField(auto_now_add=True)
